package com.gxgeek.javabasic.Thread;

/**
 * @author gaoxing
 * @create 2018-06-02 下午2:19
 */
public class ThreadLocalTest {
    public static void main(String[] args) throws  Exception{
//        final ThreadLocal<String> threadLocal=new ThreadLocal<String>();
//        threadLocal.set("Java架构沉思录");
//        System.out.println("父线程的值："+threadLocal.get());
//        new Thread(new Runnable() {
//            @Override
//            public void run() {
//                System.out.println("子线程的值："+threadLocal.get());
//            }
//        }).start();
//
//        Thread.sleep(2000);

        final ThreadLocal<String> threadLocal=new InheritableThreadLocal<>();
        threadLocal.set("Java架构沉思录");
        System.out.println("父线程的值："+threadLocal.get());
        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("子线程的值："+threadLocal.get());
            }
        }).start();

        Thread.sleep(2000);

    }

}
